import { IFeidaoAiNodejsComponent } from '@dfeidao/atom-nodejs/interfaces';
import format from '@dfeidao/atom-web/dt/format';

import nodejs from '@dfeidao/atom-web/msg/nodejs';


import render from '@dfeidao/atom-nodejs/render/render';
import p001 from './p001';
import p003 from './p003';

import p002 from './p002';

import set from '@dfeidao/atom-web/global/set';


export default async function na001(fd: IFeidaoAiNodejsComponent, e: Event) {
	// todo
	const res = await nodejs<{ res: Array<{work_bill_no: string,project_name: string,responsible: string,job_content: string, completion_time: number }>, t: number }>('knowledge-base/zj-000001/s001', {
		filter: {
			pn: 1
		}
	});
	// 日期转格式
	const ral = res.res.map((n) => {
		return { ...n, completion_time: format(n.completion_time, 2) };
	});


	if (res.res.length > 0) {
		render(fd.data.node,ral, p001, 'p001');
		if (res.t > 20) {
			render(fd.data.node, res.t, p003, 'p003');
		}


	} else {
		render(fd.data.node, '', p002, 'p002');
	}

	const users = { staff_no: 'YG00000077', staff_name: '梁日星', productid: 'kinth_cloud_100' };
	const staff_name = users.staff_name;
	const staff_no = users.staff_no;
	const productid = users.productid;
	const dta = { staff_no, staff_name, productid };
	set('dta', dta);

}
